using HKB.Common;
using HKB.Data.Dal.S_AdZoneTableAdapters;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class AdZoneBll
	{
		private Conn conn = null;
		private static readonly HL_AdZoneTableAdapter Adapter = new HL_AdZoneTableAdapter();
		public AdZoneBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public AdZoneBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetAllZone()
		{
			string sql = "SELECT * From [HL_AdZone]";
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetSingeAdZone(int AdZoneID)
		{
			string commandText = "SELECT * From [HL_AdZone] Where ([ZoneID] = @ZoneID)";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ZoneID", DbType.Int32, AdZoneID);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public bool UpdateAdZone(int ChannelID, string ZoneName, string ZoneJSName, string ZoneIntro, int ZoneType, bool DafaultSetting, string ZoneSetting, int ZoneWidth, int ZoneHeight, bool Active, int ShowType, DateTime UpDateTime, int ZoneID)
		{
			int num = AdZoneBll.Adapter.UpdateZone(new int?(ChannelID), ZoneName, ZoneJSName, ZoneIntro, new int?(ZoneType), DafaultSetting, ZoneSetting, new int?(ZoneWidth), new int?(ZoneHeight), Active, new int?(ShowType), UpDateTime, ZoneID);
			return num > 0;
		}
		public int InnerAdZone(int ChannelID, string ZoneName, string ZoneJSName, string ZoneIntro, int ZoneType, bool DafaultSetting, string ZoneSetting, int ZoneWidth, int ZoneHeight, bool Active, int ShowType, DateTime UpDateTime)
		{
			return int.Parse(AdZoneBll.Adapter.GetZoneID(new int?(ChannelID), ZoneName, ZoneJSName, ZoneIntro, new int?(ZoneType), new bool?(DafaultSetting), ZoneSetting, new int?(ZoneWidth), new int?(ZoneHeight), new bool?(Active), new int?(ShowType), new DateTime?(UpDateTime)).Rows[0]["ZoneID"].ToString());
		}
		public bool DelectAdZone(int AdZoneID)
		{
			string commandText = "DELETE From [HL_AdZone] Where ([ZoneID] = @ZoneID)";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ZoneID", DbType.Int32, AdZoneID);
			int num = this.conn.Execute(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
			return num > 0;
		}
		public void DeleteAdZones(string ZoneIDArr)
		{
			AdZoneBll.Adapter.DeleteAdZones(ZoneIDArr);
		}
		public void MoveAdZoneChannel(int ChannelID, string ZoneIDArr)
		{
			AdZoneBll.Adapter.MoveAdZoneChannel(new int?(ChannelID), ZoneIDArr);
		}
		public void SetAdZoneActive(string ZoneIDArr)
		{
			AdZoneBll.Adapter.SetAdZoneActive(ZoneIDArr);
		}
		public void SetAdZoneUnActive(string ZoneIDArr)
		{
			AdZoneBll.Adapter.SetAdZoneUnActive(ZoneIDArr);
		}
		public DataTable GetAdZoneByNameIntro(string ZoneName, int? Zonetype)
		{
			return AdZoneBll.Adapter.GetAdZoneByNameIntro(ZoneName, Zonetype);
		}
		public DataTable GetJsNameByChannelID(int ChanelID)
		{
			DataTable jsNameByChannelID = AdZoneBll.Adapter.GetJsNameByChannelID(new int?(ChanelID));
			DataTable dataTable = new DataTable();
			DataColumn dataColumn = new DataColumn();
			dataColumn.ColumnName = "ZoneJSName";
			DataColumn dataColumn2 = new DataColumn();
			dataColumn2.ColumnName = "ZoneName";
			dataTable.Columns.Add(dataColumn);
			dataTable.Columns.Add(dataColumn2);
			for (int i = 0; i < jsNameByChannelID.Rows.Count; i++)
			{
				DataRow dataRow = dataTable.NewRow();
				for (int j = 0; j < jsNameByChannelID.Columns.Count; j++)
				{
					if (jsNameByChannelID.Columns[j].ColumnName == "ZoneJSName")
					{
						dataRow["ZoneJSName"] = string.Concat(new string[]
						{
							"<script type=\"text/javascript\" src=\"http://",
							HttpContext.Current.Request.Url.Host.ToString(),
							"/IMS_AD/",
							jsNameByChannelID.Rows[i]["ZoneJSName"].ToString(),
							"\"></script>"
						});
					}
					else
					{
						dataRow["ZoneName"] = jsNameByChannelID.Rows[i]["ZoneName"].ToString();
					}
				}
				dataTable.Rows.Add(dataRow);
			}
			return dataTable;
		}
		public DataTable GetAllActiveAdZone()
		{
			DataTable allActiveAdZone = AdZoneBll.Adapter.GetAllActiveAdZone();
			DataTable dataTable = new DataTable();
			DataColumn dataColumn = new DataColumn();
			dataColumn.ColumnName = "ZoneJSName";
			DataColumn dataColumn2 = new DataColumn();
			dataColumn2.ColumnName = "ZoneName";
			dataTable.Columns.Add(dataColumn);
			dataTable.Columns.Add(dataColumn2);
			for (int i = 0; i < allActiveAdZone.Rows.Count; i++)
			{
				DataRow dataRow = dataTable.NewRow();
				for (int j = 0; j < allActiveAdZone.Columns.Count; j++)
				{
					if (allActiveAdZone.Columns[j].ColumnName == "ZoneJSName")
					{
						dataRow["ZoneJSName"] = string.Concat(new string[]
						{
							"<script type=\"text/javascript\" src=\"http://",
							HttpContext.Current.Request.Url.Host.ToString(),
							"/IMS_AD/",
							allActiveAdZone.Rows[i]["ZoneJSName"].ToString(),
							"\"></script>"
						});
					}
					else
					{
						dataRow["ZoneName"] = allActiveAdZone.Rows[i]["ZoneName"].ToString();
					}
				}
				dataTable.Rows.Add(dataRow);
			}
			return dataTable;
		}
		public DataTable GetZoneByZoneID(string ZoneIDArray)
		{
			if (ZoneIDArray.LastIndexOf(",") == ZoneIDArray.Length - 1)
			{
				ZoneIDArray = ZoneIDArray.Remove(ZoneIDArray.Length - 1);
			}
			DataTable result;
			if (Text.CheckNumList(ZoneIDArray, ','))
			{
				string sql = "select * from hl_ADZone where ZoneID in(" + ZoneIDArray + ")";
				result = this.conn.GetDataTable(sql);
			}
			else
			{
				result = null;
			}
			return result;
		}
	}
}
